package sk7;

public class SuperArray {


    private Object [] objs = new Object[0];
    /**
     * 获取数组长度的方法
     * @return
     */
    public int size(){
        return objs.length;
    }

    /**
     * 根据下标获取指定元素
     * @param index
     * @return
     */
    public Object get(int index){
        return objs[index];
    }
    /**
     * 将指定值添加到超级数组的尾部
     * @param value
     */
    public void add(Object value){

        Object [] newObjs = new Object[objs.length + 1];
        for(int i = 0;i < objs.length;i++){
            newObjs[i] = objs[i];
        }
        newObjs[newObjs.length - 1] = value;
        objs = newObjs;
    }

    /**
     * 根据指定下标删除数组中的某个元素
     * @param index
     */
    public void remove(int index){
        Object [] newAry = new Object[objs.length - 1];
        for(int i = 0;i < newAry.length;i++){
            if(i < index){
                newAry[i] = objs[i];
            }else{
                newAry[i] = objs[i+1];
            }
        }
        objs = newAry;
    }
    }

